package tech.yangzhijie.basic.knowledge.other;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class AtomicTest {

    public static void main(String[] args) {
        //atomic();
        test();
    }

    private static void atomic(){
        AtomicDemo atomicDemo = new AtomicDemo();
        for (int i = 0; i < 200; i++) {
            new Thread(atomicDemo).start();
        }
    }

    private static void test(){
        String s = "1,2,3,4,5,6,7,8,9,11,10,12,13,14,16,15,18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,33,32,34,35,36,37,38,39,40,41,42,70,68,75,78,69,67,66,65,62,64,63,61,59,60,57,58,55,56,54,53,52,51,43,85,48,50,49,47,45,46,44,43,88,87,86,84,83,82,81,80,79,77,74,76,73,72,71,90,89,91,92,93,94,95,97,98,99,96,101,100,105,103,102,104,107,106,108,109,111,110,112,113,114,117,116,115,118,119,120,121,124,125,123,122,126,128,127,130,133,132,131,129,134,135,136,137,139,138,140,141,154,155,159,153,161,162,152,151,149,150,148,147,145,146,144,143,142,163,160,158,157,156,164,165,166,167,168,169,171,173,175,170,174,172,176,177,178,180,179,181,182,184,183,185,187,186,188,189,190,191,192,197,196,198,199,195,193,194";
        String[] split = s.split(",");
        Set<String> set = new HashSet<>(200);
        List<String> list = Arrays.asList(split);
        for (String str : list) {
            set.add(str);
        }
        System.out.println("list: " + list.size());
        System.out.println("set: " + set.size());
    }
}

class AtomicDemo implements Runnable {

    private AtomicInteger atomicInteger = new AtomicInteger(1);

    @Override
    public void run() {
        try {

            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.print(getAtomicInteger() + ",");
    }

    public int getAtomicInteger() {
        return atomicInteger.getAndIncrement();
    }
}